package com.sphd.Restaurant.presenter;

import android.widget.Toast;

import com.android.volley.VolleyError;
import com.sphd.Restaurant.infos.LoginInfo;
import com.sphd.Restaurant.interfFace.VolleyCallBack;
import com.sphd.Restaurant.utils.VolleyErrorHelper;
import com.sphd.Restaurant.views.LoginV;


import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Hu on 2016/9/28.
 */

public class LoginP extends BasePresenter implements VolleyCallBack<JSONObject> {
    LoginV loginV;

    public LoginP(LoginV loginV) {
        this.loginV = loginV;
    }

    @Override
    public void onResponse(JSONObject jsonObject) {
        try {
            if ("[]".equals(jsonObject.getString("loginInfo"))) {
                loginV.LoginError();
            } else {
                LoginInfo loginInfo = myJson.getLoginInfo(jsonObject);
                loginV.LoginOk(loginInfo);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        loginV.dissmissdialog();
    }

    @Override
    public void onErrorResponse(VolleyError error) {

        Toast.makeText(context, VolleyErrorHelper.getMessage(error),Toast.LENGTH_SHORT).show();loginV.dissmissdialog();
    }

    @Override
    public void addData(String url) {
        loginV.showdialog();
        sendJsonObjectUrl(url, this);
    }
}
